
clear

cd "C:\code"

import delimited datasetdiff.txt, delimiters(tab) clear

*label variables
label variable deaths_per_capita "Deaths Per Capita"
*label variable weekly_incr_deaths_per_capita "Weekly Change in Deaths Per Capita"
label variable stayhome "Stay at Home"
label variable emergency "State of Emergency"
label variable nursingmustaccept "Nursing Accept Pos."
label variable novisit "No Nursing Visits"
*label variable schoolshut "Schools Closed"
label variable employeemask "Employees Masks"
label variable maskrec "Masks Recommended"
label variable maskmandatory "Mandatory Masks"
label variable parksclosed "Beaches or Parks Closed"
label variable openreverse "Re-openings Reversed"
label variable noelective "No Elective Procedures"
label variable restclosed "Restaurants Closed"
label variable barsclosed "Bars Closed"
label variable gymsclosed "Gyms Closed"
label variable spasclosed "Spas Closed"
label variable gathermax10 "Gatherings Limited to 10"
label variable gathermax100 "No Gatherings Over 100"
label variable gathermax100plus "No Gatherings Limit>100"
label variable medriskclose "Med. Risk Bus. Closed"
label variable highriskclose "High Risk Bus. Closed"
label variable higherriskclose "Higher Risk Bus. Closed"
label variable highestriskclose "Highest Risk Bus. Closed"
label variable percapincome "Per Capita Income"
label variable popdensity "Population Density"
label variable obese "Obesity"
label variable smoke "Smokers"
label variable housingdensity "Housing Density"
label variable t_first "Days Since First Case"
label variable deaths7_growth "Growth{\sub t+1}"
label variable deaths14_growth "Growth{\sub t+2}"
label variable deaths21_growth "Growth{\sub t+3}"
label variable deaths28_growth "Growth{\sub t+4}"
label variable deaths35_growth "Growth{\sub t+5}"
label variable deaths42_growth "Growth{\sub t+6}"
label variable deaths7_lgrowth "Growth{\sub t-1}"
label variable deaths14_lgrowth "Growth{\sub t-2}"
label variable deaths21_lgrowth "Growth{\sub t-3}"
label variable deaths28_lgrowth "Growth{\sub t-4}"
label variable deaths35_lgrowth "Growth{\sub t-5}"
label variable deaths42_lgrowth "Growth{\sub t-6}"
label variable deaths7_per_cap_lag "Deaths Per Cap{\sub t-1}"
label variable deaths14_per_cap_lag "Deaths Per Cap{\sub t-2}"
label variable deaths21_per_cap_lag "Deaths Per Cap{\sub t-3}"
label variable deaths28_per_cap_lag "Deaths Per Cap{\sub t-4}"
label variable deaths35_per_cap_lag "Deaths Per Cap{\sub t-5}"
label variable deaths42_per_cap_lag "Deaths Per Cap{\sub t-6}"
label variable t "Days Since March 1"
label variable avgtemp "Avg Temperature"
label variable hothumidweekdays "Hot Humid Weekdays"
label variable nursetotpop "Nursing Home Pop."
label variable hothumidweekend "Hot Humid Weekend"
label variable coldweekday "Cold Weekdays"
label variable coldweekend "Cold Weekend"
label variable age65plus "Age 65+"
label variable age85plus "Age 85+"
label variable asian "Asian"
label variable black "Black"
label variable hispanic "Hispanic"
label variable nativeamer "Native Americans"
label variable other "Other"

gen date1 = date(date, "DM20Y") 
format date1 %td
drop if date1 > mdy(12,31,2020)
drop if date1 < mdy(3,1,2020)

drop if missing(deaths42_lgrowth)

*regression (1 week)

reg deaths7_growth deaths_per_capita deaths7_lgrowth deaths14_lgrowth deaths21_lgrowth deaths28_lgrowth deaths35_lgrowth deaths42_lgrowth t_first t avgtemp hothumidweekdays hothumidweekend coldweekday coldweekend age65plus age85plus asian black hispanic nativeamer other percapincome popdensity diabetes obese smoke housingdensity nursetotpop stayhome emergency nursingmustaccept novisit  employeemask  maskrec maskmandatory parksclosed openreverse noelective restclosed barsclosed gymsclosed spasclosed  gathermax10 gathermax100 gathermax100plus medriskclose highriskclose higherriskclose highestriskclose log_wks_stayhome log_wks_emergency  log_wks_nursingmustaccept log_wks_novisit log_wks_employeemask log_wks_maskrec log_wks_maskmandatory log_wks_parksclosed log_wks_openreverse log_wks_noelective log_wks_restclosed log_wks_barsclosed log_wks_gymsclosed log_wks_spasclosed log_wks_gathermax10 log_wks_gathermax100 log_wks_gathermax100plus log_wks_medriskclose log_wks_highriskclose log_wks_higherriskclose log_wks_highestriskclose wks_stayhome wks_emergency wks_nursingmustaccept wks_novisit wks_employeemask wks_maskrec wks_maskmandatory wks_parksclosed wks_openreverse wks_noelective wks_restclosed wks_barsclosed wks_gymsclosed wks_spasclosed wks_gathermax10 wks_gathermax100 wks_gathermax100plus wks_medriskclose wks_highriskclose wks_higherriskclose wks_highestriskclose, vce(cluster countyfips)


*stayhome 
    frame create CI weeks impact orlb orub
	
forvalues a = 1(1)16 {

    scalar c = ln(`a' + 1)
    lincom `a'*wks_stayhome + c*log_wks_stayhome

    frame post CI (`a') (`r(estimate)') (`r(lb)') (`r(ub)')
}
    frame change CI

graph twoway (connect impact weeks, sort) (rcap orlb orub weeks), name(stayhome, replace) xlabel(1(1)16) xtitle("Weeks") ytitle("Change in deaths per 10,000") title("Stay Home") graphregion(color(white)) legend(off)


*emergency 
    clear frames
 	frame create CI weeks impact orlb orub
	
forvalues a = 1(1)16 {

    scalar c = ln(`a'+ 1)
    lincom `a'*wks_emergency + c*log_wks_emergency

    frame post CI (`a') (`r(estimate)') (`r(lb)') (`r(ub)')
}
    frame change CI

graph twoway (connect impact weeks, sort) (rcap orlb orub weeks), name(emergency, replace) xlabel(1(1)16) xtitle("Weeks") ytitle("Change in deaths per 10,000") title("Emergency") graphregion(color(white)) legend(off)


*nursingmustaccept 
    clear frames
 	frame create CI weeks impact orlb orub
	
forvalues a = 1(1)16 {

    scalar c = ln(`a'+ 1)
    lincom `a'*wks_nursingmustaccept + c*log_wks_nursingmustaccept

    frame post CI (`a') (`r(estimate)') (`r(lb)') (`r(ub)')
}
    frame change CI

graph twoway (connect impact weeks, sort) (rcap orlb orub weeks), name(nursingmustaccept, replace) xlabel(1(1)16) xtitle("Weeks") ytitle("Change in deaths per 10,000") title("Nursing Home Must Accept Positives") graphregion(color(white)) legend(off)


*novisit 
    clear frames
 	frame create CI weeks impact orlb orub
	
forvalues a = 1(1)16 {

    scalar c = ln(`a'+ 1)
    lincom `a'*wks_novisit + c*log_wks_novisit

    frame post CI (`a') (`r(estimate)') (`r(lb)') (`r(ub)')
}
    frame change CI

graph twoway (connect impact weeks, sort) (rcap orlb orub weeks), name(novisit, replace) xlabel(1(1)16) xtitle("Weeks") ytitle("Change in deaths per 10,000") title("No Nursing Home Visits") graphregion(color(white)) legend(off)


*employeemask 
    clear frames
 	frame create CI weeks impact orlb orub
	
forvalues a = 1(1)16 {

    scalar c = ln(`a'+ 1)
    lincom `a'*wks_employeemask + c*log_wks_employeemask

    frame post CI (`a') (`r(estimate)') (`r(lb)') (`r(ub)')
}
    frame change CI

graph twoway (connect impact weeks, sort) (rcap orlb orub weeks), name(employeemask, replace) xlabel(1(1)16) xtitle("Weeks") ytitle("Change in deaths per 10,000") title("Employees Must Wear Masks") graphregion(color(white)) legend(off)


*maskrec 
    clear frames
 	frame create CI weeks impact orlb orub
	
forvalues a = 1(1)16 {

    scalar c = ln(`a'+ 1)
    lincom `a'*wks_maskrec + c*log_wks_maskrec

    frame post CI (`a') (`r(estimate)') (`r(lb)') (`r(ub)')
}
    frame change CI

graph twoway (connect impact weeks, sort) (rcap orlb orub weeks), name(maskrec, replace) xlabel(1(1)16) xtitle("Weeks") ytitle("Change in deaths per 10,000") title("Masks Recommended in Public") graphregion(color(white)) legend(off)


*maskmandatory 
    clear frames
 	frame create CI weeks impact orlb orub
	
forvalues a = 1(1)16 {

    scalar c = ln(`a'+ 1)
    lincom `a'*wks_maskmandatory + c*log_wks_maskmandatory

    frame post CI (`a') (`r(estimate)') (`r(lb)') (`r(ub)')
}
    frame change CI

graph twoway (connect impact weeks, sort) (rcap orlb orub weeks), name(maskmandatory, replace) xlabel(1(1)16) xtitle("Weeks") ytitle("Change in deaths per 10,000") title("Mandatory Masks in Public") graphregion(color(white)) legend(off)


*parksclosed 
    clear frames
 	frame create CI weeks impact orlb orub
	
forvalues a = 1(1)16 {

    scalar c = ln(`a'+ 1)
    lincom `a'*wks_parksclosed + c*log_wks_parksclosed

    frame post CI (`a') (`r(estimate)') (`r(lb)') (`r(ub)')
}
    frame change CI

graph twoway (connect impact weeks, sort) (rcap orlb orub weeks), name(parksclosed, replace) xlabel(1(1)16) xtitle("Weeks") ytitle("Change in deaths per 10,000") title("Beaches and Parks Closed") graphregion(color(white)) legend(off)


*noelective 
    clear frames
 	frame create CI weeks impact orlb orub
	
forvalues a = 1(1)16 {

    scalar c = ln(`a'+ 1)
    lincom `a'*wks_noelective + c*log_wks_noelective

    frame post CI (`a') (`r(estimate)') (`r(lb)') (`r(ub)')
}
    frame change CI

graph twoway (connect impact weeks, sort) (rcap orlb orub weeks), name(noelective, replace) xlabel(1(1)16) xtitle("Weeks") ytitle("Change in deaths per 10,000") title("No Elective Procedures") graphregion(color(white)) legend(off)


*restclosed 
    clear frames
 	frame create CI weeks impact orlb orub
	
forvalues a = 1(1)16 {

    scalar c = ln(`a'+ 1)
    lincom `a'*wks_restclosed + c*log_wks_restclosed

    frame post CI (`a') (`r(estimate)') (`r(lb)') (`r(ub)')
}
    frame change CI

graph twoway (connect impact weeks, sort) (rcap orlb orub weeks), name(restclosed, replace) xlabel(1(1)16) xtitle("Weeks") ytitle("Change in deaths per 10,000") title("Restaurants and Bars Closed") graphregion(color(white)) legend(off)


*barsclosed 
    clear frames
 	frame create CI weeks impact orlb orub
	
forvalues a = 1(1)16 {

    scalar c = ln(`a'+ 1)
    lincom `a'*wks_barsclosed + c*log_wks_barsclosed

    frame post CI (`a') (`r(estimate)') (`r(lb)') (`r(ub)')
}
    frame change CI

graph twoway (connect impact weeks, sort) (rcap orlb orub weeks), name(barsclosed, replace) xlabel(1(1)16) xtitle("Weeks") ytitle("Change in deaths per 10,000") title("Bars Closed/Restaurants Open") graphregion(color(white)) legend(off)


*gymsclosed 
    clear frames
 	frame create CI weeks impact orlb orub
	
forvalues a = 1(1)16 {

    scalar c = ln(`a'+ 1)
    lincom `a'*wks_gymsclosed + c*log_wks_gymsclosed

    frame post CI (`a') (`r(estimate)') (`r(lb)') (`r(ub)')
}
    frame change CI

graph twoway (connect impact weeks, sort) (rcap orlb orub weeks), name(gymsclosed, replace) xlabel(1(1)16) xtitle("Weeks") ytitle("Change in deaths per 10,000") title("Gyms Closed") graphregion(color(white)) legend(off)


*spasclosed 
    clear frames
 	frame create CI weeks impact orlb orub
	
forvalues a = 1(1)16 {

    scalar c = ln(`a'+ 1)
    lincom `a'*wks_spasclosed + c*log_wks_spasclosed

    frame post CI (`a') (`r(estimate)') (`r(lb)') (`r(ub)')
}
    frame change CI

graph twoway (connect impact weeks, sort) (rcap orlb orub weeks), name(spasclosed, replace) xlabel(1(1)16) xtitle("Weeks") ytitle("Change in deaths per 10,000") title("Spas Closed") graphregion(color(white)) legend(off)


*gathermax10 
    clear frames
 	frame create CI weeks impact orlb orub
	
forvalues a = 1(1)16 {

    scalar c = ln(`a'+ 1)
    lincom `a'*wks_gathermax10 + c*log_wks_gathermax10

    frame post CI (`a') (`r(estimate)') (`r(lb)') (`r(ub)')
}
    frame change CI

graph twoway (connect impact weeks, sort) (rcap orlb orub weeks), name(gathermax10, replace) xlabel(1(1)16) xtitle("Weeks") ytitle("Change in deaths per 10,000") title("Gatherings Limited to 10") graphregion(color(white)) legend(off)


*gathermax100 
    clear frames
 	frame create CI weeks impact orlb orub
	
forvalues a = 1(1)16 {

    scalar c = ln(`a'+ 1)
    lincom `a'*wks_gathermax100 + c*log_wks_gathermax100

    frame post CI (`a') (`r(estimate)') (`r(lb)') (`r(ub)')
}
    frame change CI

graph twoway (connect impact weeks, sort) (rcap orlb orub weeks), name(gathermax100, replace) xlabel(1(1)16) xtitle("Weeks") ytitle("Change in deaths per 10,000") title("No Gatherings Over 100") graphregion(color(white)) legend(off)


*gathermax100plus 
    clear frames
 	frame create CI weeks impact orlb orub
	
forvalues a = 1(1)16 {

    scalar c = ln(`a'+ 1)
    lincom `a'*wks_gathermax100plus + c*log_wks_gathermax100plus

    frame post CI (`a') (`r(estimate)') (`r(lb)') (`r(ub)')
}
    frame change CI

graph twoway (connect impact weeks, sort) (rcap orlb orub weeks), name(gathermax100plus, replace) xlabel(1(1)16) xtitle("Weeks") ytitle("Change in deaths per 10,000") title("No Gatherings and Limit>100") graphregion(color(white)) legend(off)


*medriskclose 
    clear frames
 	frame create CI weeks impact orlb orub
	
forvalues a = 1(1)16 {

    scalar c = ln(`a'+ 1)
    lincom `a'*wks_medriskclose + c*log_wks_medriskclose

    frame post CI (`a') (`r(estimate)') (`r(lb)') (`r(ub)')
}
    frame change CI

graph twoway (connect impact weeks, sort) (rcap orlb orub weeks), name(medriskclose, replace) xlabel(1(1)16) xtitle("Weeks") ytitle("Change in deaths per 10,000") title("Risk Level 1 Closed") graphregion(color(white)) legend(off)


*highriskclose 
    clear frames
 	frame create CI weeks impact orlb orub
	
forvalues a = 1(1)16 {

    scalar c = ln(`a'+ 1)
    lincom `a'*wks_highriskclose + c*log_wks_highriskclose

    frame post CI (`a') (`r(estimate)') (`r(lb)') (`r(ub)')
}
    frame change CI

graph twoway (connect impact weeks, sort) (rcap orlb orub weeks), name(highriskclose, replace) xlabel(1(1)16) xtitle("Weeks") ytitle("Change in deaths per 10,000") title("Risk Level 2 Closed") graphregion(color(white)) legend(off)


*higherriskclose 
    clear frames
 	frame create CI weeks impact orlb orub
	
forvalues a = 1(1)16 {

    scalar c = ln(`a'+ 1)
    lincom `a'*wks_higherriskclose + c*log_wks_higherriskclose

    frame post CI (`a') (`r(estimate)') (`r(lb)') (`r(ub)')
}
    frame change CI

graph twoway (connect impact weeks, sort) (rcap orlb orub weeks), name(higherriskclose, replace) xlabel(1(1)16) xtitle("Weeks") ytitle("Change in deaths per 10,000") title("Risk Level 3 Closed") graphregion(color(white)) legend(off)


*highestriskclose 
    clear frames
 	frame create CI weeks impact orlb orub
	
forvalues a = 1(1)16 {

    scalar c = ln(`a'+ 1)
    lincom `a'*wks_highestriskclose + c*log_wks_highestriskclose

    frame post CI (`a') (`r(estimate)') (`r(lb)') (`r(ub)')
}
    frame change CI

graph twoway (connect impact weeks, sort) (rcap orlb orub weeks), name(highestriskclose, replace) xlabel(1(1)16) xtitle("Weeks") ytitle("Change in deaths per 10,000") title("Risk Level 4 Closed") graphregion(color(white)) legend(off)


*openreverse 
    clear frames
 	frame create CI weeks impact orlb orub
	
forvalues a = 1(1)16 {

    scalar c = ln(`a'+ 1)
    lincom `a'*wks_openreverse + c*log_wks_openreverse

    frame post CI (`a') (`r(estimate)') (`r(lb)') (`r(ub)')
}
    frame change CI

graph twoway (connect impact weeks, sort) (rcap orlb orub weeks), name(openreverse, replace) xlabel(1(1)16) xtitle("Weeks") ytitle("Change in deaths per 10,000") title("Business Re-openings Reversed") graphregion(color(white)) legend(off)
